﻿'Description: SubtitleUtilsTest class
'Authors: George Birbilis (birbilis@kagi.com)
'Version: 20090310

Imports System.Text

Imports Microsoft.VisualStudio.TestTools.UnitTesting

Imports LvS.objects.subtitles
Imports LvS.models.subtitles
Imports LvS.utilities.subtitles

'''<summary>
'''This is a test class for SubtitleUtilsTest and is intended
'''to contain all SubtitleUtilsTest tests
'''</summary>
<TestClass()> _
Public Class SubtitleUtilsTest

	Private testContextInstance As TestContext

	'''<summary>
	'''Gets or sets test context which provides
	'''information about and functionality for current test run
	'''</summary>
	Public Property TestContext() As TestContext
		Get
			Return testContextInstance
		End Get
		Set(ByVal value As TestContext)
			testContextInstance = Value
		End Set
	End Property

#Region "TTS"

	'''<summary>
	'''TTS read test
	'''</summary>
	<TestMethod()> _
Public Sub Read_TTS_Test()
		ReadSubtitlesTest("sample.tts", Encoding.Default)
	End Sub

	'''<summary>
	'''TTS write test
	'''</summary>
	<TestMethod()> _
	Public Sub Write_TTS_Test()
		WriteSubtitlesTest("sample.tts", Encoding.Default)
	End Sub

	'''<summary>
	'''TTS read test (UTF8)
	'''</summary>
	<TestMethod()> _
Public Sub Read_TTS_UTF8_Test()
		ReadSubtitlesTest("sample.tts", Encoding.UTF8)
	End Sub

	'''<summary>
	'''TTS write test (UTF8)
	'''</summary>
	<TestMethod()> _
	Public Sub Write_TTS_UTF8_Test()
		WriteSubtitlesTest("sample.tts", Encoding.UTF8)
	End Sub

#End Region

#Region "SRT"

	'''<summary>
	'''SRT read test
	'''</summary>
	<TestMethod()> _
Public Sub Read_SRT_Test()
		ReadSubtitlesTest("sample.SRT", Encoding.Default)
	End Sub

	'''<summary>
	'''SRT write test
	'''</summary>
	<TestMethod()> _
	Public Sub Write_SRT_Test()
		WriteSubtitlesTest("sample.SRT", Encoding.Default)
	End Sub

	'''<summary>
	'''SRT read test (UTF8)
	'''</summary>
	<TestMethod()> _
Public Sub Read_SRT_UTF8_Test()
		ReadSubtitlesTest("sample.SRT", Encoding.UTF8)
	End Sub

	'''<summary>
	'''SRT write test (UTF8)
	'''</summary>
	<TestMethod()> _
	Public Sub Write_SRT_UTF8_Test()
		WriteSubtitlesTest("sample.SRT", Encoding.UTF8)
	End Sub

#End Region

	'#Region "FAB"

	'	'''<summary>
	'	'''FAB write test
	'	'''</summary>
	'	<TestMethod()> _
	'	Public Sub Write_FAB_Test()
	'		WriteSubtitlesTest("sample.FAB", Encoding.Default)
	'	End Sub

	'	'''<summary>
	'	'''FAB write test (UTF8)
	'	'''</summary>
	'	<TestMethod()> _
	'	Public Sub Write_FAB_UTF8_Test()
	'		WriteSubtitlesTest("sample.FAB", Encoding.UTF8)
	'	End Sub

	'#End Region

	'#Region "Encore"

	'	'''<summary>
	'	'''Encore write test
	'	'''</summary>
	'	<TestMethod()> _
	'	Public Sub Write_Encore_Test()
	'		WriteSubtitlesTest("sample.ENC", Encoding.Default)
	'	End Sub

	'	'''<summary>
	'	'''Encore write test (UTF8)
	'	'''</summary>
	'	<TestMethod()> _
	'	Public Sub Write_Encore_UTF8_Test()
	'		WriteSubtitlesTest("sample.ENC", Encoding.UTF8)
	'	End Sub

	'#End Region

#Region "Utilities"

	Private Sub ReadSubtitlesTest(ByVal path As String, ByVal theEncoding As Encoding)
		WriteSubtitlesTest(path, theEncoding)	'same testing for reading & writing for now with autogenerated samples
	End Sub

	Private Sub WriteSubtitlesTest(ByVal path As String, ByVal theEncoding As Encoding)
		Dim subtitles As ISubtitles = New Subtitles()
		For i As Integer = 0 To 10
			subtitles.Add(New Subtitle(i, i + 1))
		Next i
		Try
			SubtitleUtils.WriteSubtitles(subtitles, path, theEncoding)
			Dim subtitles2 As ISubtitles = New Subtitles()
			SubtitleUtils.ReadSubtitles(subtitles2, path, theEncoding)
			Assert.IsTrue(subtitles.Count = subtitles2.Count)
		Catch e As Exception
			Assert.Fail(e.Message)
		End Try
	End Sub

#End Region

End Class
